package com.ruoyi.parttime.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.parttime.domain.vo.ApplyForParrtimeVo;
import com.ruoyi.parttime.service.IApplyForParrtimeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 兼职申请Controller
 *
 * @author ruoyi
 * @date 2024-04-02
 */
@RestController
@RequestMapping("/user/applyfor")
@Api(tags = "我的兼职申请")
public class ApplyForParrtimeController extends BaseController {
    @Autowired
    private IApplyForParrtimeService applyForParrtimeService;

    /**
     * 查询兼职申请列表
     */
    @PreAuthorize("@ss.hasPermi('common:myapplyfor:list')")
    @GetMapping("/myapplyfor/list")
//    @Anonymous
    @ApiOperation(value = "查询兼职申请列表")
    public TableDataInfo list(ApplyForParrtimeVo applyForParrtimeVo) {
        startPage();
        List<ApplyForParrtimeVo> list = applyForParrtimeService.selectApplyForParrtimeList(applyForParrtimeVo);
        return getDataTable(list);
    }

    /**
     * 导出兼职申请列表
     */
    @PreAuthorize("@ss.hasPermi('common:myapplyfor:export')")
    @Log(title = "兼职申请", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "导出兼职申请列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApplyForParrtimeVo applyForParrtimeVo) {
        List<ApplyForParrtimeVo> list = applyForParrtimeService.selectApplyForParrtimeList(applyForParrtimeVo);
        ExcelUtil<ApplyForParrtimeVo> util = new ExcelUtil<ApplyForParrtimeVo>(ApplyForParrtimeVo.class);
        util.exportExcel(response, list, "兼职申请数据");
    }

    /**
     * 批量撤销兼职申请，直接删除此数据
     */
    @PreAuthorize("@ss.hasPermi('common:myapplyfor:remove')")
    @Log(title = "兼职申请", businessType = BusinessType.DELETE)
    @ApiOperation(value = "批量撤销兼职申请")
    @DeleteMapping("/batch/{ids}")
    public AjaxResult batchRemove(@PathVariable Long[] ids) {
        return toAjax(applyForParrtimeService.deleteApplyForParrtimeByparttimePublishIds(ids));
    }

    /**
     * 撤销兼职申请，直接删除此数据
     */
    @PreAuthorize("@ss.hasPermi('common:myapplyfor:remove')")
    @Log(title = "兼职申请", businessType = BusinessType.DELETE)
    @ApiOperation(value = "撤销兼职申请")
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id) {
        return toAjax(applyForParrtimeService.deleteApplyForParrtimeById(id));
    }
}
